﻿@using KL.Store.Core
@{
    Layout = "~/Views/Shared/" + Parameters.Layout + ".cshtml";
    var cssClass = "col-xs-12 col-sm-12 col-md-3 col-lg-2 left first last";
    var pSort = 4;
    var pOrder = 2;
    if (Parameters.Theme == "DK")
    {
        cssClass = "col-xs-12 col-sm-12 col-md-4 col-lg-3 left first";
    }
    else if (Parameters.Theme == "EO")
    {
        cssClass = "col-xs-12 col-sm-12 col-md-4 col-lg-3 left first";
    }
    else if (Parameters.Theme == "WU")
    {
        cssClass = "col-xs-12 col-sm-12 col-md-3 col-lg-3 left";
    }
    else if (Parameters.Theme == "JB")
    {
        pSort = 3;
        pOrder = 2;
    }
}
<div class="@cssClass">
    @if (Parameters.ShowCategoryOnProductsPages)
    {
        Html.RenderAction("Categories", "Partials");
    }
    @if (Parameters.ShowBrandSelection)
    {
        Html.RenderAction("Brands", "Partials");
    }
    <form name="product-filter" method="get">
        <div class="product-filter" id="allfilters">
            <div class="product-filter-inner">
                <h5 class="product-filter-title">Seçimleriniz</h5>
                <ul class="price-range-inputs-all">
                </ul>
            </div>
        </div>
        @if (Parameters.ShowBrandFilter || ViewBag.IsManager || ViewBag.IsSeoManager)
        {
            Html.RenderAction("GetBrandsSelection", "Products", new { id = ViewContext.RouteData.Values["id"] });
        }
        @{ Html.RenderAction("GetPropertyFilter", "Products", new { id = ViewContext.RouteData.Values["id"] }); }
        <div class="product-filter">
            <div class="product-filter-inner">
                <h5 class="product-filter-title">Fiyat Aralığı  @if (!Parameters.ShowPriceRangeAsCheckbox)
                                                                {<text>(TL)</text>}</h5>
                <div class="product-filter-options radiotype">
                    <ul class="price-range-inputs" @{ if (Parameters.ShowPriceRangeAsCheckbox)
                                                      {<text>style="display:none;"</text>} }>
                        <li>
                            <input type="text" name="enAzUcret" id="enAzUcret" class="form-control" disabled="disabled" />
                        </li>
                        <li class="price-range-and">ve</li>
                        <li>
                            <input type="text" name="enFazlaucret" id="enFazlaucret" class="form-control" disabled="disabled" />
                        </li>
                    </ul>
                    @if (Parameters.ShowPriceRangeAsCheckbox)
                    {
                        <ul class="price-range-check">
                        </ul>
                    }
                    <div class="clearfix"></div>
                    @if (!Parameters.ShowPriceRangeAsCheckbox)
                    {
                        <div id="price-range"></div>
                    }
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
        @{ Html.RenderAction("GetPropertySelection", "Products", new { id = ViewContext.RouteData.Values["id"] }); }
    </form>
</div>
<div id="content">
    @{ Html.RenderAction("Get", "Products", new { id = ViewContext.RouteData.Values["id"], brand = ViewContext.RouteData.Values["brand"], sort = pSort, order = pOrder, itemCount = Parameters.MaxProductCountForPage, ColumnCount = ViewBag.ColumnCount, ListImageType = ViewBag.ListImageType, ShowcaseGroup = ViewBag.ShowcaseGroup }); }
</div>
<script>
    var minPriceDefault = 0;
    if ((parseInt($('#minPriceDefault').val()) - 1) >= 0)
    {
        minPriceDefault = parseInt($('#minPriceDefault').val()) - 1;
    }
    var maxPriceDefault = parseInt($('#maxPriceDefault').val()) + 1;
    var selectedMinPrice = parseInt('@(ViewBag.MinPrice)');
    var selectedMaxPrice = parseInt('@(ViewBag.MaxPrice)');

    function showAllFilters()
    {
        //sıfırla
        $('.product-filter#allfilters ul.price-range-inputs-all').html('');
        //getir
        $('.product-filter-option-brand ul li input[type=checkbox]:checked').each(function ()
        {
            addFilterElementToAllFilters('Marka', $(this).parent().find('label').html(), 'marka', $(this).attr('id'));
        });
        if ($('.price-range-check').size() > 0 && $('.price-range-check li input[type=checkbox]:checked').size() > 0)
        {
            addFilterElementToAllFilters('Fiyat Aralığı', $('.price-range-check li input[type=checkbox]:checked').parent().find('label').html(), 'fiyat-araligi', $('.price-range-check li input[type=checkbox]:checked').attr('id'));
        }
        $('.product-filter-option-property ul li input[type=checkbox]:checked').each(function ()
        {
            addFilterElementToAllFilters($(this).parent().parent().parent().parent().parent().parent().find('h5').html(), $(this).parent().find('label').html(), 'property', $(this).attr('id'));
        });

        $('.product-filter-option-others ul li input[type=checkbox]:checked').each(function ()
        {
            addFilterElementToAllFilters($(this).parent().parent().parent().parent().parent().parent().find('h5').html(), $(this).parent().find('label').html(), 'others', $(this).attr('id'));
        });

        //göster gizle
        if ($('.product-filter#allfilters ul.price-range-inputs-all li').size() > 0)
        {
            $('.product-filter#allfilters').css({ 'display': 'block' });
        }
        else
        {
            $('.product-filter#allfilters').css({ 'display': 'none' });
        }
    }
    function addFilterElementToAllFilters(isim, icerik, tip, id)
    {
        $('.product-filter#allfilters ul.price-range-inputs-all').append('<li class="filtertype-' + tip + '"><span class="filter-name">' + isim + '</span><span class="filter-content">' + icerik + '</span><i class="fa fa-close removefilter" data-id="' + id + '"></i></li>');
    }
    $('.product-filter#allfilters ul.price-range-inputs-all li .removefilter').live('click', function ()
    {
        var id = $(this).data('id');
        if ($('#' + id).hasClass('singleFilterSelect'))
        {
            $('#' + id).prop("checked", false).triggerHandler('change');
        }
        else
        {
            $('#' + id).prop("checked", false).triggerHandler('click');
        }
        showAllFilters();
    });
    $(document).ready(function ()
    {
        showAllFilters();
    });
</script>
@if (Parameters.ShowPriceRangeAsCheckbox)
{
    <script>

        $(function ()
        {
            if (minPriceDefault < 50)
            {
                var aralik50Ch = (selectedMinPrice > 0 && selectedMaxPrice < 50) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik050" data-min="0" data-max="50" ' + aralik50Ch + ' /><label for="aralik050">0 TL - 50 TL</label></li>');
            }
            if (maxPriceDefault >= 50 && minPriceDefault <= 100)
            {
                var aralik50100Ch = (selectedMinPrice >= 50 && selectedMaxPrice <= 100) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik50100" data-min="50" data-max="100" ' + aralik50100Ch + ' /><label for="aralik50100">50 TL - 100 TL</label></li>');
            }
            if (maxPriceDefault >= 100 && minPriceDefault <= 250)
            {
                var aralik100250Ch = (selectedMinPrice >= 100 && selectedMaxPrice <= 250) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik100250" data-min="100" data-max="250" ' + aralik100250Ch + ' /><label for="aralik100250">100 TL - 250 TL</label></li>');
            }
            if (maxPriceDefault >= 250 && minPriceDefault <= 500)
            {
                var aralik250500Ch = (selectedMinPrice >= 250 && selectedMaxPrice <= 500) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik250500" data-min="250" data-max="500" ' + aralik250500Ch + ' /><label for="aralik250500">250 TL - 500 TL</label></li>');
            }
            if (maxPriceDefault >= 500 && minPriceDefault <= 750)
            {
                var aralik500750Ch = (selectedMinPrice >= 500 && selectedMaxPrice <= 750) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik500750" data-min="500" data-max="750" ' + aralik500750Ch + ' /><label for="aralik500750">500 TL - 750 TL</label></li>');
            }
            if (maxPriceDefault >= 750 && minPriceDefault <= 1000)
            {
                var aralik7501000Ch = (selectedMinPrice >= 750 && selectedMaxPrice <= 1000) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik7501000" data-min="750" data-max="1000" ' + aralik7501000Ch + ' /><label for="aralik7501000">750 TL - 1000 TL</label></li>');
            }
            if (maxPriceDefault >= 1000 && minPriceDefault <= 1500)
            {
                var aralik10001500Ch = (selectedMinPrice >= 1000 && selectedMaxPrice <= 1500) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik10001500" data-min="1000" data-max="1500" ' + aralik10001500Ch + ' /><label for="aralik10001500">1000 TL - 1500 TL</label></li>');
            }
            if (maxPriceDefault >= 1500 && minPriceDefault <= 2500)
            {
                var aralik15002500Ch = (selectedMinPrice >= 1500 && selectedMaxPrice <= 2500) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik15002500" data-min="1500" data-max="2500" ' + aralik15002500Ch + ' /><label for="aralik15002500">1500 TL - 2500 TL</label></li>');
            }
            if (maxPriceDefault >= 2500 && minPriceDefault <= 5000)
            {
                var aralik25005000Ch = (selectedMinPrice >= 2500 && selectedMaxPrice <= 5000) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik25005000" data-min="2500" data-max="5000" ' + aralik25005000Ch + ' /><label for="aralik25005000">2500 TL - 5000 TL</label></li>');
            }
            if (maxPriceDefault >= 5000 && minPriceDefault <= 10000)
            {
                var aralik500010000Ch = (selectedMinPrice >= 5000 && selectedMaxPrice <= 10000) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input class="product-range-input-check singleFilterSelect" type="checkbox" id="aralik500010000" data-min="5000" data-max="10000" ' + aralik500010000Ch + ' /><label for="aralik500010000">5000 TL - 10000 TL</label></li>');
            }
            if (maxPriceDefault >= 10000)
            {
                var aralik1000plusCh = (selectedMinPrice >= 5000) ? ' checked="checked"' : '';
                $('.price-range-check').append('<li><input type="checkbox" id="aralik1000plus" data-min="10000" data-max="9999999999" ' + aralik1000plusCh + ' /><label for="aralik1000plus">10000\'den Fazla</label></li>');
            }

            $(".product-range-input-check").change(function ()
            {
                var checkedInputId = $(this).attr("id");
                var checkedFound = false;
                $(".product-range-input-check").each(function ()
                {
                    if ($(this).attr("id") != checkedInputId)
                    {
                        $(this).attr("checked", false);
                    }
                    if ($(this).attr("checked"))
                    {
                        checkedFound = true;
                    }
                });
                if (checkedFound)
                {
                    $("#enAzUcret").val($(this).attr("data-min"));
                    $("#enFazlaucret").val($(this).attr("data-max"));
                }
                else
                {
                    $("#enAzUcret").val(0);
                    $("#enFazlaucret").val(99999999999);
                }
                SortMinMaxPrice();
            });
            showAllFilters();
            $(".product-filter-options").customScrollbar();
            $(".product-filter-options .scroll-bar .thumb").html("<div class=\"thumb-image\"></div>");
        });


    </script>
}
else
{
    <script>
        $("#price-range").slider({
            range: true,
            min: minPriceDefault,
            max: maxPriceDefault,
            values: [(selectedMinPrice != minPriceDefault ? selectedMinPrice : minPriceDefault), (selectedMaxPrice != maxPriceDefault ? selectedMaxPrice : maxPriceDefault)],
            slide: function (event, ui)
            {
                $("#enAzUcret").val(ui.values[0]);
                $("#enFazlaucret").val(ui.values[1]);
            },
            change: function (event, ui)
            {
                SortMinMaxPrice();
            }
        });
        $("#enAzUcret").val($("#price-range").slider("values", 0));
        $("#enFazlaucret").val($("#price-range").slider("values", 1));
    </script>
}